from tkinter import *
import tkinter.filedialog
import tkinter.messagebox

import bilibiliVideoUtil

root = Tk()
root.title('B站手机缓存视频转换工具')

root.geometry('500x300')

sourceVal = StringVar()
targetVal = StringVar()


# 选择资源文件
def selectSource(value):
    # filename = tkinter.filedialog.askopenfilename()
    filename = tkinter.filedialog.askdirectory()
    if filename != '':
        value.set(filename)
    else:
        # 未选择
        tkinter.messagebox.showwarning(title='warn', message='您什么也没选!')


def selectSourceA():
    selectSource(sourceVal)


def selectSourceB():
    selectSource(targetVal)


def transferFile():
    tmp = bilibiliVideoUtil.Video_utils(sourceVal.get(), targetVal.get())
    result = tmp.transfer()
    tkinter.messagebox.showinfo(title='warn', message=result.message)


# 源文件夹选择
Label(root, text='源文件夹', font=('Arial', 14), width=8, height=1).place(x=20, y=60)
Entry(root, textvariable=sourceVal, font=('Arial', 14), width=20).place(x=120, y=60)
Button(root, text='选择', font=('Arial', 10), width=4, command=selectSourceA).place(x=350, y=60)

# 目标文件夹选择
Label(root, text='目标文件夹', font=('Arial', 14), width=8, height=1).place(x=20, y=120)
Entry(root, textvariable=targetVal, font=('Arial', 14), width=20).place(x=120, y=120)
Button(root, text='选择', font=('Arial', 10), width=4, command=selectSourceB).place(x=350, y=120)

Button(root, text='开始转换', font=('Arial', 16), width=10, command=transferFile).place(x=160, y=180)

root.mainloop()
